import {defineStore} from 'pinia'
/*
*   菜单相关的
*/

export const useMneu = defineStore('useMneu', {
    state: () => {
        return {
            menulist: [
                {
                    label: '我的',
                    key: '1',
                    children: [
                        {
                            label: '首页', key: 'Shouye', children: [
                                {label: '工作台', key: 'Workflat'},
                                {label: '仪表台', key: 'Meterflat'},
                                {label: '监控台', key: 'Monitorflat'},
                                {label: '测试区', key: 'Myceshi'},
                            ],
                        },
                        {
                            label: '我的流程', key: 'Myapply', children: [
                                {label: '发起流程', key: 'Startapply'},
                                {label: '待办流程', key: 'Administrativeprocess'},
                                {label: '我的申请', key: 'Myapply'},
                            ],
                        },
                        {
                            label: '我的考勤', key: 'Mykaoqin',
                        },
                        {
                            label: '我的资产', key: 'Myzichan',
                        },
                        {
                            label: '我的日程', key: 'Myricheng',
                        },
                        {
                            label: '我的资料', key: 'Myinfo', children: [
                                {label: '个人信息', key: 'Userinfo'},
                                {label: '账号信息', key: 'Workerinfo'},
                                {label: '登录日志', key: 'Loginlog'},
                                {label: '操作日志', key: 'Actionlog'},
                            ],
                        },
                    ],
                },
                {
                    label: '人事',
                    key: '2',
                    children: [
                        {label: '员工管理', key: 'Workermanager'},
                        {label: '转岗管理', key: 'Transferpost',children:[
                                {label: '转岗申请', key: 'Transferapply'},
                                {label: '转岗审批', key: 'Transferapproval'},
                            ],},
                    ],
                },
                {
                    label: '行政',
                    key: '3',
                    children: [
                        {
                            label: '会议管理',
                            key: '32',
                            children: [
                                {
                                    label: '会议室管理',
                                    key: 'Meetroom',
                                },
                                {
                                    label: '会议管理',
                                    key: '321',
                                },
                            ],
                        },
                    ],
                },
                {
                    label: '销售',
                    key: '4',
                    children: [],
                },
                {
                    label: '财务',
                    key: '5',
                    children: [],
                },
                {
                    label: '仓储',
                    key: '6',
                    children: [],
                },
                {
                    label: '设置',
                    key: '7',
                    children: [
                        {label: '字典管理', key: 'Dictmanager'},
                        {label: '菜单管理', key: 'Menumanager'},
                        {label: '部门管理', key: 'Departmanager'},
                        {label: '职位管理', key: 'Positionmanager'},
                        {label: '地区管理', key: 'Areamanager'},
                        {label: '权限管理', key: 'Permissionmanager'},
                        {label: '代码生成', key: 'Createcode'},
                        {
                            label: '门户管理', key: 'gateway', children: [
                                {label: '首页管理', key: 'shouyemanager'},
                                {label: '产品管理', key: 'chanpinmanager'},
                                {label: '招聘管理', key: 'zhaopinmanager'},
                                {label: '联系信息', key: 'Lxwm'},
                                {label: '关于我们', key: 'Gywm'},
                            ],
                        },
                        {label: '公司信息管理', key: 'Companyinfo'},
                        {
                            label: '公司考试管理', key: 'Kaoshimanagement', children: [
                                {label: '考试管理', key: 'Examinationmanagement'},
                                {label: '试卷管理', key: 'Testpapermanagement'},
                                {label: '成绩管理', key: 'Performancemanagement'},
                            ]
                        },
                    ],
                },
            ],
            firstmenu: '',
        }
    },
    actions: {
        // 点击顶部导航切换当前激活项
        chengemeu(key: string) {
            console.log('点击', key)
            this.firstmenu = key
        },
        // 切换路由的时候，顶部导航也一块切换
        routeChange(name: string) {
            const qiehuan = (list1: Array<any>, activekey: string) => {
                list1.forEach(item => {
                    if (item.key === name) {
                        this.firstmenu = activekey
                    } else if (item.children && item.children.length > 0) {
                        qiehuan(item.children, activekey)
                    }
                })
            }
            this.menulist.forEach((item: { key: string, label: string, children: Array<any> }): void => {
                if (item.children && item.children.length > 0) {
                    qiehuan(item.children, item.key)
                }
            })
        }
    },
    // pinia持久化
    persist: {
        key: 'mymenu',    // 加密
        storage: window.sessionStorage, // 存储位置
    },
})
